package com.cg.w3d1.controller;

import com.cg.w3d1.bean.Employee;
import com.cg.w3d1.dao.EmployeeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Controller
@RequestMapping("/")
public class EmployeeController {
    @Autowired
    EmployeeDao employeeDao;

    @ResponseBody
    @RequestMapping("employees")
    public List<Employee> getAll(){
        List list = new ArrayList();
        Collection<Employee> employees = employeeDao.getAll();
        for (Employee employee : employees) {
            list.add(employee);
        }
        return list;
    }
    @ResponseBody
    @RequestMapping("emp")
    public Employee getOne(){


        return employeeDao.getEmpById(1);
    }
}
